const path = require('path');
const log4js = require('koa-log4');
let baseDir='back-end/logs/';
log4js.configure({
    appenders: {
        access: {
            type: 'dateFile',
            pattern: '-yyyy-MM-dd.log', //生成文件的规则
            filename: path.join(baseDir, 'access.log') //生成文件名
        },
        applicationInfo: {
            type: 'dateFile',
            pattern: '-yyyy-MM-dd-info.log',
            filename: path.join(baseDir, 'application-info.log')
        },
        applicationError: {
            type: 'dateFile',
            pattern: '-yyyy-MM-dd.log',
            filename: path.join(baseDir, 'application-error.log')
        },
        out: {
            type: 'console'
        }
    },
    categories: {
        default: {appenders: ['out'], level: 'info'},
        access: {appenders: ['access'], level: 'info'},
        applicationInfo: {appenders: ['applicationInfo'], level: 'info'},
        applicationError: {appenders: ['applicationError'], level: 'warn'}
    }
});

// let config = {
//     accessLogger: ()=>log4js.koaLogger(log4js.getLogger('access')),
//     infoLogger: log4js.getLogger('out')|| log4js.getLogger('applicationInfo'),
//     errorLogger:log4js.getLogger('out') || log4js.getLogger('applicationError'),
//     con: log4js.getLogger('out')
// };

//exports.accessLogger = () => log4js.koaLogger(log4js.getLogger('access')); //记录所有访问级别的日志
//exports.systemLogger = log4js.getLogger('application');  //记录所有应用级别的日志

module.exports =log4js;
